package com.shujia.spark.mllib

import org.apache.spark.ml.feature.LabeledPoint
import org.apache.spark.ml.linalg
import org.apache.spark.ml.linalg.{SparseVector, Vectors}

object Demo1Vector {
  def main(args: Array[String]): Unit = {

    //向量代表数据中的特征（特征向量）
    //稠密向量
    val dense: linalg.Vector = Vectors.dense(Array(1.2, 0, 0, 0, 0, 0, 0, 2.2, 123.22, 0, 0, 0, 2))
    println(dense)

    //稀疏向量:只保存非0的值
    val sparse: SparseVector = dense.toSparse
    println(sparse)

    val sparseVec: linalg.Vector = Vectors.sparse(100, Array(1, 2, 6), Array(1.4, 21.23, 123.2))
    println(sparseVec)
    println(sparseVec.toDense)

    //label: 目标值（y）
    //features: 特征向量(x)
    val point: LabeledPoint = LabeledPoint(1.0, Vectors.dense(Array(1.1, 2.3, 22.1)))
    println(point)
  }
}
